let app = getApp();
Page({
  data: {
    orderInfo:null,
    imageList:[],
    priceVal:0,
    focusFlag:false,
    orderId:'',
    openid:'',
    comment:''
  },
  onLoad(options) {
  let that = this;
    app.get('DingDanDiZhi',{
      action:'getDingDanById',
      id: options.orderId
    }).then((res)=>{
      let detail = res.listmingxi,listArr = [];
      for (let i in detail){        
        listArr.push(detail[i].listurl[0].Url)
      }
      that.setData({
        orderInfo:res,
        priceVal: res.YouHuiJinE,
        imageList: listArr,
        orderId: options.orderId
      });
    });
    wx.getStorage({
      key: 'openid',
      success(res) {
        that.setData({
          openid:res.data
        })
      },
    })
  },
   previewImage(e) {
    var current = e.target.dataset.src
    wx.previewImage({
      current: current,
      urls: this.data.imageList
    });
  },
  priceInput(e){
    this.setData({
      priceVal: e.detail.value
    });
  },
  amendPrice(){
    this.setData({
      focusFlag:true
    });
  },
  submitAmend(){
    let that = this;
    app.get('DingDanDiZhi',{
      action:'editzongjine',
      openid:that.data.openid,
      id: that.data.orderId,
      youhuijine: that.data.priceVal,
      youhuibeizhu: that.data.comment,
    }).then((res)=>{
      console.log(res)
      if (res.msg ==="申请成功！"){  
        wx.navigateBack({
          delta:1
        });
        app.toast(res.msg);
      }else{
        app.toast('申请失败!')
        }
    })
  }
})